//
//  Shebei_offline_popView.m
//  MMPopupView
//
//  Created by Ralph Li on 9/6/15.
//  Copyright © 2015 LJC. All rights reserved.
//

#import "Shebei_offline_popView.h"
#import "MMPopupItem.h"
#import "MMPopupCategory.h"
#import "MMPopupDefine.h"
#import "MMPopupWindow.h"
#import <Masonry/Masonry.h>

@interface Shebei_offline_popView()

@property (nonatomic, strong) UIView      *backView;

@property (nonatomic, strong) UILabel     *tip_lb;

@property (nonatomic, strong) UIButton    *btnConfirm;
@property (nonatomic, strong) UIButton    *btnClose;

@property (nonatomic, strong)UIImageView *tip_iv;

@end

@implementation Shebei_offline_popView

- (instancetype)init
{
    self = [super init];
    
    if ( self )
    {
        self.type = MMPopupTypeCustom;
        
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(ScreenWidth - 80, 250 * (ScreenWidth - 80) / 305));
        }];
        
        
        
        self.backView = [UIView new];
        [self addSubview:self.backView];
        [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        self.backView.layer.cornerRadius = 5.0f;
        self.backView.clipsToBounds = YES;
        self.backView.backgroundColor = [UIColor whiteColor];
        
        self.tip_iv = [UIImageView new];
        [self.backView addSubview:self.tip_iv];
        CGFloat tip_iv_w = (ScreenWidth - 80) * 92 / 305;
        [self.tip_iv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.backView.mas_top).offset(30);
            make.centerX.mas_equalTo(self.backView);
            make.size.mas_equalTo(CGSizeMake( tip_iv_w, (tip_iv_w * 68 / 92)));
        }];
        
        
        self.tip_lb = [UILabel new];
        self.tip_lb.numberOfLines = 0;
        [self.tip_lb setAdjustsFontSizeToFitWidth:YES];
        [self.backView addSubview:self.tip_lb];
        [self.tip_lb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.tip_iv.mas_bottom).offset(16);
            make.left.right.mas_equalTo(self.backView);
            make.height.equalTo(@50);
        }];
        self.tip_lb.textColor = themeColor;
        self.tip_lb.font = [UIFont systemFontOfSize:20];

        self.tip_lb.textAlignment = NSTextAlignmentCenter;
        
        
        self.btnClose = [UIButton mm_buttonWithTarget:self action:@selector(actionClose)];
        [self.backView addSubview:self.btnClose];
        [self.btnClose mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.backView.mas_right).offset(-16);
            make.bottom.mas_equalTo(self.backView.mas_bottom).offset(-20);
            make.size.mas_equalTo(CGSizeMake(120, 50));
        }];
        [self.btnClose setTitle:@"取消" forState:UIControlStateNormal];
        [self.btnClose setTitleColor:themeColor forState:UIControlStateNormal];
        self.btnClose.titleLabel.font = [UIFont systemFontOfSize:18];
        self.btnClose.layer.masksToBounds = YES;
        self.btnClose.layer.cornerRadius = 4;
        self.btnClose.layer.borderWidth = 1;
        self.btnClose.layer.borderColor = themeColor.CGColor;
        
        self.btnConfirm = [UIButton mm_buttonWithTarget:self action:@selector(actionConfirm)];
        [self.backView addSubview:self.btnConfirm];
        [self.btnConfirm mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.backView.mas_left).offset(16);
            make.bottom.mas_equalTo(self.backView.mas_bottom).offset(-20);            make.size.mas_equalTo(self.btnClose);
        }];
        [self.btnConfirm setTitle:@"确定" forState:UIControlStateNormal];
        [self.btnConfirm setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [self.btnConfirm setBackgroundColor:themeColor];
        self.btnConfirm.titleLabel.font = [UIFont systemFontOfSize:18];
        self.btnConfirm.layer.masksToBounds = YES;
        self.btnConfirm.layer.cornerRadius = 4;
        self.btnConfirm.layer.borderWidth = 1;
        self.btnConfirm.layer.borderColor = themeColor.CGColor;
    
    }
    
    return self;
}

- (void)setImg_name:(NSString *)img_name{
    _img_name = img_name;
    self.tip_iv.image = [UIImage imageNamed:img_name];

}
- (void)setTipStr:(NSString *)tipStr{
    _tipStr = tipStr;
    self.tip_lb.text = tipStr;

}

- (void)setQueren_btn_title_str:(NSString *)queren_btn_title_str{
    _queren_btn_title_str  = queren_btn_title_str;
    [self.btnConfirm setTitle:queren_btn_title_str forState:UIControlStateNormal];

}

- (void)actionClose
{
    [self hide];
    if (self.btnBlock) {
        self.btnBlock(self, NO);
    }
}
- (void)actionConfirm
{
    [self hide];
    if (self.btnBlock) {
        self.btnBlock(self, YES);
    }
    
}



@end
